#include "oled_ui.h"

static void OLED_Show_Building(int16_t X, int16_t Y, uint8_t building_map_select)
{
    OLED_ShowChinese(X, Y, get_building_map_index(building_map_select));
    char *remain_index = get_building_map_remain_index(building_map_select);
    OLED_Printf(X + 16, Y, OLED_8X16, "%s ", remain_index);
    // 释放内存，防止内存泄漏
    // free(remain_index);
}

static void building_map_menu(uint8_t select_map)
{
    OLED_Clear();
    OLED_ShowImage(10, 0, 32, 32, gImage_building);
    OLED_ShowChinese(11, 38, "楼栋");
    switch (select_map)
    {
    case SOUTH_1:
        OLED_Show_Building(64, 0, SOUTH_1);
        OLED_Show_Building(64, 16, SOUTH_2);
        OLED_Show_Building(64, 32, SOUTH_3);
        OLED_Show_Building(64, 48, SOUTH_4);
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case SOUTH_2:
        OLED_Show_Building(64, 0, SOUTH_1);
        OLED_Show_Building(64, 16, SOUTH_2);
        OLED_Show_Building(64, 32, SOUTH_3);
        OLED_Show_Building(64, 48, SOUTH_4);
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case SOUTH_3:
        OLED_Show_Building(64, 0, SOUTH_1);
        OLED_Show_Building(64, 16, SOUTH_2);
        OLED_Show_Building(64, 32, SOUTH_3);
        OLED_Show_Building(64, 48, SOUTH_4);
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case SOUTH_4:
        OLED_Show_Building(64, 0, SOUTH_1);
        OLED_Show_Building(64, 16, SOUTH_2);
        OLED_Show_Building(64, 32, SOUTH_3);
        OLED_Show_Building(64, 48, SOUTH_4);
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case SOUTH_5:
        OLED_Show_Building(64, 0, SOUTH_5);
        OLED_Show_Building(64, 16, SOUTH_6);
        OLED_Show_Building(64, 32, SOUTH_7);
        OLED_Show_Building(64, 48, SOUTH_8);
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case SOUTH_6:
        OLED_Show_Building(64, 0, SOUTH_5);
        OLED_Show_Building(64, 16, SOUTH_6);
        OLED_Show_Building(64, 32, SOUTH_7);
        OLED_Show_Building(64, 48, SOUTH_8);
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case SOUTH_7:
        OLED_Show_Building(64, 0, SOUTH_5);
        OLED_Show_Building(64, 16, SOUTH_6);
        OLED_Show_Building(64, 32, SOUTH_7);
        OLED_Show_Building(64, 48, SOUTH_8);
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case SOUTH_8:
        OLED_Show_Building(64, 0, SOUTH_5);
        OLED_Show_Building(64, 16, SOUTH_6);
        OLED_Show_Building(64, 32, SOUTH_7);
        OLED_Show_Building(64, 48, SOUTH_8);
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case CENTER_1A:
        OLED_Show_Building(64, 0, CENTER_1A);
        OLED_Show_Building(64, 16, CENTER_1B);
        OLED_Show_Building(64, 32, CENTER_1C);
        OLED_Show_Building(64, 48, CENTER_1D);
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case CENTER_1B:
        OLED_Show_Building(64, 0, CENTER_1A);
        OLED_Show_Building(64, 16, CENTER_1B);
        OLED_Show_Building(64, 32, CENTER_1C);
        OLED_Show_Building(64, 48, CENTER_1D);
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case CENTER_1C:
        OLED_Show_Building(64, 0, CENTER_1A);
        OLED_Show_Building(64, 16, CENTER_1B);
        OLED_Show_Building(64, 32, CENTER_1C);
        OLED_Show_Building(64, 48, CENTER_1D);
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case CENTER_1D:
        OLED_Show_Building(64, 0, CENTER_1A);
        OLED_Show_Building(64, 16, CENTER_1B);
        OLED_Show_Building(64, 32, CENTER_1C);
        OLED_Show_Building(64, 48, CENTER_1D);
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case EAST_20:
        OLED_Show_Building(64, 0, EAST_20);
        OLED_Show_Building(64, 16, EAST_21);
        OLED_Show_Building(64, 32, EAST_22);
        OLED_Show_Building(64, 48, EAST_23);
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case EAST_21:
        OLED_Show_Building(64, 0, EAST_20);
        OLED_Show_Building(64, 16, EAST_21);
        OLED_Show_Building(64, 32, EAST_22);
        OLED_Show_Building(64, 48, EAST_23);
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case EAST_22:
        OLED_Show_Building(64, 0, EAST_20);
        OLED_Show_Building(64, 16, EAST_21);
        OLED_Show_Building(64, 32, EAST_22);
        OLED_Show_Building(64, 48, EAST_23);
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case EAST_23:
        OLED_Show_Building(64, 0, EAST_20);
        OLED_Show_Building(64, 16, EAST_21);
        OLED_Show_Building(64, 32, EAST_22);
        OLED_Show_Building(64, 48, EAST_23);
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    }
}

/**
 * @brief 显示楼层选择菜单
 * 南5-南8 8层
 * 南1-南4 中1A-中1D 7层
 * 东20-东21 12层
 * 东22-东23 15层
 */
static void building_floor_menu(uint8_t building_map_select, uint8_t select_floor)
{
    OLED_Clear();
    OLED_ShowImage(10, 0, 32, 32, gImage_floor);
    OLED_ShowChinese(11, 38, "楼层");
    OLED_Printf(7, 56, OLED_6X8, "(01-15)");
    // 选择南1-南4 中1A-中1D 楼栋 7层
    if ((building_map_select <= SOUTH_4) || (building_map_select >= CENTER_1A && building_map_select <= CENTER_1D))
    {
        switch (select_floor)
        {
        case 1:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 2:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 3:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 4:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 5:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 6:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 7:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        }
    }
    else if (building_map_select >= SOUTH_5 && building_map_select <= SOUTH_8)
    {
        switch (select_floor)
        {
        case 1:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 2:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 3:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 4:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 5:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 6:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 7:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 8:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        }
    }
    else if (building_map_select >= EAST_20 && building_map_select <= EAST_21)
    {
        switch (select_floor)
        {
        case 1:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 2:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 3:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 4:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 5:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 6:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 7:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 8:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 9:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 10:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 11:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 12:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        }
    }
    else if (building_map_select >= EAST_22 && building_map_select <= EAST_23)
    {
        switch (select_floor)
        {
        case 1:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 2:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 3:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 4:
            OLED_Printf(64, 0, OLED_8X16, "1 ");
            OLED_Printf(64, 16, OLED_8X16, "2 ");
            OLED_Printf(64, 32, OLED_8X16, "3 ");
            OLED_Printf(64, 48, OLED_8X16, "4 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 5:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 6:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 7:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 8:
            OLED_Printf(64, 0, OLED_8X16, "5 ");
            OLED_Printf(64, 16, OLED_8X16, "6 ");
            OLED_Printf(64, 32, OLED_8X16, "7 ");
            OLED_Printf(64, 48, OLED_8X16, "8 ");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 9:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 10:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 11:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        case 12:
            OLED_Printf(64, 0, OLED_8X16, "9 ");
            OLED_Printf(64, 16, OLED_8X16, "10");
            OLED_Printf(64, 32, OLED_8X16, "11");
            OLED_Printf(64, 48, OLED_8X16, "12");
            OLED_ReverseArea(64, 48, 64, 16);
            OLED_Update();
            break;
        case 13:
            OLED_Printf(64, 0, OLED_8X16, "13");
            OLED_Printf(64, 16, OLED_8X16, "14");
            OLED_Printf(64, 32, OLED_8X16, "15");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 0, 64, 16);
            OLED_Update();
            break;
        case 14:
            OLED_Printf(64, 0, OLED_8X16, "13");
            OLED_Printf(64, 16, OLED_8X16, "14");
            OLED_Printf(64, 32, OLED_8X16, "15");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 16, 64, 16);
            OLED_Update();
            break;
        case 15:
            OLED_Printf(64, 0, OLED_8X16, "13");
            OLED_Printf(64, 16, OLED_8X16, "14");
            OLED_Printf(64, 32, OLED_8X16, "15");
            OLED_Printf(64, 48, OLED_8X16, "  ");
            OLED_ReverseArea(64, 32, 64, 16);
            OLED_Update();
            break;
        }
    }
}

static void building_room_menu(uint8_t select_room)
{
    OLED_Clear();
    OLED_ShowImage(10, 0, 32, 32, gImage_room);
    OLED_ShowChinese(6, 40, "房间号");
    OLED_Printf(8, 56, OLED_6X8, "(01-30)");
    switch (select_room)
    {
    case 1:
        OLED_Printf(64, 0, OLED_8X16, "1 ");
        OLED_Printf(64, 16, OLED_8X16, "2 ");
        OLED_Printf(64, 32, OLED_8X16, "3 ");
        OLED_Printf(64, 48, OLED_8X16, "4 ");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 2:
        OLED_Printf(64, 0, OLED_8X16, "1 ");
        OLED_Printf(64, 16, OLED_8X16, "2 ");
        OLED_Printf(64, 32, OLED_8X16, "3 ");
        OLED_Printf(64, 48, OLED_8X16, "4 ");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 3:
        OLED_Printf(64, 0, OLED_8X16, "1 ");
        OLED_Printf(64, 16, OLED_8X16, "2 ");
        OLED_Printf(64, 32, OLED_8X16, "3 ");
        OLED_Printf(64, 48, OLED_8X16, "4 ");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 4:
        OLED_Printf(64, 0, OLED_8X16, "1 ");
        OLED_Printf(64, 16, OLED_8X16, "2 ");
        OLED_Printf(64, 32, OLED_8X16, "3 ");
        OLED_Printf(64, 48, OLED_8X16, "4 ");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 5:
        OLED_Printf(64, 0, OLED_8X16, "5 ");
        OLED_Printf(64, 16, OLED_8X16, "6 ");
        OLED_Printf(64, 32, OLED_8X16, "7 ");
        OLED_Printf(64, 48, OLED_8X16, "8 ");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 6:
        OLED_Printf(64, 0, OLED_8X16, "5 ");
        OLED_Printf(64, 16, OLED_8X16, "6 ");
        OLED_Printf(64, 32, OLED_8X16, "7 ");
        OLED_Printf(64, 48, OLED_8X16, "8 ");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 7:
        OLED_Printf(64, 0, OLED_8X16, "5 ");
        OLED_Printf(64, 16, OLED_8X16, "6 ");
        OLED_Printf(64, 32, OLED_8X16, "7 ");
        OLED_Printf(64, 48, OLED_8X16, "8 ");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 8:
        OLED_Printf(64, 0, OLED_8X16, "5 ");
        OLED_Printf(64, 16, OLED_8X16, "6 ");
        OLED_Printf(64, 32, OLED_8X16, "7 ");
        OLED_Printf(64, 48, OLED_8X16, "8 ");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 9:
        OLED_Printf(64, 0, OLED_8X16, "9 ");
        OLED_Printf(64, 16, OLED_8X16, "10");
        OLED_Printf(64, 32, OLED_8X16, "11");
        OLED_Printf(64, 48, OLED_8X16, "12");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 10:
        OLED_Printf(64, 0, OLED_8X16, "9 ");
        OLED_Printf(64, 16, OLED_8X16, "10");
        OLED_Printf(64, 32, OLED_8X16, "11");
        OLED_Printf(64, 48, OLED_8X16, "12");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 11:
        OLED_Printf(64, 0, OLED_8X16, "9 ");
        OLED_Printf(64, 16, OLED_8X16, "10");
        OLED_Printf(64, 32, OLED_8X16, "11");
        OLED_Printf(64, 48, OLED_8X16, "12");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 12:
        OLED_Printf(64, 0, OLED_8X16, "9 ");
        OLED_Printf(64, 16, OLED_8X16, "10");
        OLED_Printf(64, 32, OLED_8X16, "11");
        OLED_Printf(64, 48, OLED_8X16, "12");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 13:
        OLED_Printf(64, 0, OLED_8X16, "13");
        OLED_Printf(64, 16, OLED_8X16, "14");
        OLED_Printf(64, 32, OLED_8X16, "15");
        OLED_Printf(64, 48, OLED_8X16, "16");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 14:
        OLED_Printf(64, 0, OLED_8X16, "13");
        OLED_Printf(64, 16, OLED_8X16, "14");
        OLED_Printf(64, 32, OLED_8X16, "15");
        OLED_Printf(64, 48, OLED_8X16, "16");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 15:
        OLED_Printf(64, 0, OLED_8X16, "13");
        OLED_Printf(64, 16, OLED_8X16, "14");
        OLED_Printf(64, 32, OLED_8X16, "15");
        OLED_Printf(64, 48, OLED_8X16, "16");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 16:
        OLED_Printf(64, 0, OLED_8X16, "13");
        OLED_Printf(64, 16, OLED_8X16, "14");
        OLED_Printf(64, 32, OLED_8X16, "15");
        OLED_Printf(64, 48, OLED_8X16, "16");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 17:
        OLED_Printf(64, 0, OLED_8X16, "17");
        OLED_Printf(64, 16, OLED_8X16, "18");
        OLED_Printf(64, 32, OLED_8X16, "19");
        OLED_Printf(64, 48, OLED_8X16, "20");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 18:
        OLED_Printf(64, 0, OLED_8X16, "17");
        OLED_Printf(64, 16, OLED_8X16, "18");
        OLED_Printf(64, 32, OLED_8X16, "19");
        OLED_Printf(64, 48, OLED_8X16, "20");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 19:
        OLED_Printf(64, 0, OLED_8X16, "17");
        OLED_Printf(64, 16, OLED_8X16, "18");
        OLED_Printf(64, 32, OLED_8X16, "19");
        OLED_Printf(64, 48, OLED_8X16, "20");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 20:
        OLED_Printf(64, 0, OLED_8X16, "17");
        OLED_Printf(64, 16, OLED_8X16, "18");
        OLED_Printf(64, 32, OLED_8X16, "19");
        OLED_Printf(64, 48, OLED_8X16, "20");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 21:
        OLED_Printf(64, 0, OLED_8X16, "21");
        OLED_Printf(64, 16, OLED_8X16, "22");
        OLED_Printf(64, 32, OLED_8X16, "23");
        OLED_Printf(64, 48, OLED_8X16, "24");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 22:
        OLED_Printf(64, 0, OLED_8X16, "21");
        OLED_Printf(64, 16, OLED_8X16, "22");
        OLED_Printf(64, 32, OLED_8X16, "23");
        OLED_Printf(64, 48, OLED_8X16, "24");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 23:
        OLED_Printf(64, 0, OLED_8X16, "21");
        OLED_Printf(64, 16, OLED_8X16, "22");
        OLED_Printf(64, 32, OLED_8X16, "23");
        OLED_Printf(64, 48, OLED_8X16, "24");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 24:
        OLED_Printf(64, 0, OLED_8X16, "21");
        OLED_Printf(64, 16, OLED_8X16, "22");
        OLED_Printf(64, 32, OLED_8X16, "23");
        OLED_Printf(64, 48, OLED_8X16, "24");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 25:
        OLED_Printf(64, 0, OLED_8X16, "25");
        OLED_Printf(64, 16, OLED_8X16, "26");
        OLED_Printf(64, 32, OLED_8X16, "27");
        OLED_Printf(64, 48, OLED_8X16, "28");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 26:
        OLED_Printf(64, 0, OLED_8X16, "25");
        OLED_Printf(64, 16, OLED_8X16, "26");
        OLED_Printf(64, 32, OLED_8X16, "27");
        OLED_Printf(64, 48, OLED_8X16, "28");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    case 27:
        OLED_Printf(64, 0, OLED_8X16, "25");
        OLED_Printf(64, 16, OLED_8X16, "26");
        OLED_Printf(64, 32, OLED_8X16, "27");
        OLED_Printf(64, 48, OLED_8X16, "28");
        OLED_ReverseArea(64, 32, 64, 16);
        OLED_Update();
        break;
    case 28:
        OLED_Printf(64, 0, OLED_8X16, "25");
        OLED_Printf(64, 16, OLED_8X16, "26");
        OLED_Printf(64, 32, OLED_8X16, "27");
        OLED_Printf(64, 48, OLED_8X16, "28");
        OLED_ReverseArea(64, 48, 64, 16);
        OLED_Update();
        break;
    case 29:
        OLED_Printf(64, 0, OLED_8X16, "29");
        OLED_Printf(64, 16, OLED_8X16, "30");
        OLED_Printf(64, 32, OLED_8X16, "  ");
        OLED_Printf(64, 48, OLED_8X16, "   ");
        OLED_ReverseArea(64, 0, 64, 16);
        OLED_Update();
        break;
    case 30:
        OLED_Printf(64, 0, OLED_8X16, "29");
        OLED_Printf(64, 16, OLED_8X16, "30");
        OLED_Printf(64, 32, OLED_8X16, "  ");
        OLED_Printf(64, 48, OLED_8X16, "   ");
        OLED_ReverseArea(64, 16, 64, 16);
        OLED_Update();
        break;
    }
}
/**
 * @brief 显示电表数据
 *
 */
static void oled_ui_show_electricity(building_info_t *data)
{
    if (xSemaphoreTake(ml307r_init_finish_sem, 3000) == pdTRUE)
    {
        OLED_Printf(94, 32, OLED_8X16, "%u ", data->floor_num_temp * 100 + data->room_num_temp);
        OLED_Show_Building(94, 48, data->map_num_temp);
        OLED_Printf(0, 0, OLED_6X8, "remain:%.2f", ml307r_get_remain());
        OLED_Printf(0, 16, OLED_6X8, "%s ", ml307r_get_update_time());
        OLED_Printf(0, 32, OLED_6X8, "usage:%.2f", ml307r_get_usage());
        // OLED_Printf(0, 48, OLED_6X8, "%s", ml307r_get_time());
        OLED_Printf(0, 48, OLED_6X8, "bat:%.0f ", getBatteryPercent());
        OLED_Printf(50, 48, OLED_6X8, "ic:%.0f ", getIcTemp());
        OLED_Update();
        xSemaphoreGive(ml307r_init_finish_sem);
    }
}

void sleep_task(void *arg)
{
    uint8_t close_oled_flag = 0;
    EventBits_t ev_sleep;
    while (1)
    {
        ev_sleep = xEventGroupWaitBits(status_event_group, SYSTEM_SLEEP_EVENT, pdFALSE, pdFALSE, 500);
        if (ev_sleep & SYSTEM_SLEEP_EVENT && close_oled_flag == 0)
        {
            debug_printf("---------------Sleeeping mode now!---------------\r\n");
            OLED_close();
            close_oled_flag = 1;
        }
        else if (!(ev_sleep & SYSTEM_SLEEP_EVENT) && close_oled_flag == 1)
        {
            debug_printf("---------------Recover from sleeping!---------------\r\n");
            OLED_open();
            close_oled_flag = 0;
        }
    }
}

void oled_ui_task(void *arg)
{
    EventBits_t ev_sleep;
    building_info_t *data = NULL;
    OLED_Init();
    OLED_Clear();
    OLED_Update();
    xTaskCreate(btn_task, "btn_task", 128, NULL, osPriorityNormal1, NULL);
    xTaskCreate(sleep_task, "sleep_task", 128, NULL, osPriorityNormal1, NULL);
    while (1)
    {
        ev_sleep = xEventGroupWaitBits(status_event_group, SYSTEM_SLEEP_EVENT | GET_ELE_JSON_EVENT, pdFALSE, pdFALSE, 500);
        if (!(ev_sleep & SYSTEM_SLEEP_EVENT) && (ev_sleep & GET_ELE_JSON_EVENT))
        {
            xQueuePeek(building_data_QueueHandle, &data, 0);

            if (data->select_flag == NO_SELECT)
            {
                oled_ui_show_electricity(data); // 显示电表数据
            }
            else if (data->select_flag == SELECT_BUILDING_MAP)
            {
                building_map_menu(data->map_num_temp);
            }
            else if (data->select_flag == SELECT_FLOOR_NUM)
            {
                building_floor_menu(data->map_num_temp, data->floor_num_temp);
            }
            else if (data->select_flag == SELECT_ROOM_NUM)
            {
                building_room_menu(data->room_num_temp);
            }
        }
        vTaskDelay(300);
    }
}
